package com.trkj.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.YzrMedInstockDet;
import com.trkj.service.YzrInstockService;
import com.trkj.vo.Result;
import com.trkj.vo.YzrInstockVo;
import com.trkj.vo.YzrMedInstockVo;

@Controller
public class YzrInstockController {
	@Autowired
	private YzrInstockService yzrInstockService;
	
	@RequestMapping("/to_instock")
	public String toInstock(){
		return "yzr_instock";
	}
	@RequestMapping("/to_yzr_test_tu")
	public String to_yzr_test_tu(){
		return "yzr_test_tu";
	}
	
	//入库
	@RequestMapping("/ruKuMedYzr")
	public @ResponseBody Result submitRuKuMed(String[] list,String orderId,String kind,
													String store,String staffId,Date checkDate){
		yzrInstockService.submitInstockMed(list,orderId,kind,store,staffId,checkDate);
		return new Result();
	}
	
	@RequestMapping("/rukuCountYzr")
	public void rukuCount(HttpServletRequest request, HttpServletResponse response) throws IOException {
		List<YzrInstockVo> list = yzrInstockService.rukuCount();
		String start = "<chart caption='药库入库记录统计' " + "xaxisname='药品类型' yaxisname='数量' "
				+ "palettecolors='#FFFACD' bgcolor='#ffffff' " + "borderalpha='0'	canvasborderalpha='0' "
				+ "useplotgradientcolor='0' " + "plotborderalpha='10' placevaluesinside='1' "
				+ "rotatevalues='10' valuefontcolor='#000000' " + "showxaxisline='10' xaxislinecolor='#999999' "
				+ "divlinecolor='#999999' divlinedashed='10' " + "showalternatehgridcolor='0' subcaptionfontbold='0' "
				+ "	subcaptionfontsize='12'>";
		String sets = "";
		for (YzrInstockVo a : list) {
			System.err.println("value:"+a.getValue());
			System.err.println("name:"+a.getName());
			sets += "<set label='" + a.getName() + "' value='" + a.getValue() + "' color='#00CCCC' />";
		}
		String end = "</chart>";
		String all = start + sets + end;
		response.setContentType("text/plain;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(all);
		out.close();
	}
	
	//分页查询入库
	@RequestMapping("/queryAllInstockYzr")
	public @ResponseBody Map<String,Object> queryAllInstock(int page, int rows){		
		return yzrInstockService.queryAllInstock(page, rows);
	}
	
	//根据选中，查看入库信息
	@RequestMapping("/queryInstockByIdYzr")
	public @ResponseBody YzrMedInstockVo queryInstockById(String instockId){
		return yzrInstockService.queryInstockById(instockId);
	}
	
	//根据选中，查看入库详情药品
	@RequestMapping("/queryInstockDetByIdYzr")
	public @ResponseBody List<YzrMedInstockDet> queryInstockDetById(String instockId){
		return yzrInstockService.queryInstockDetById(instockId);
	}
}
